package com.cykj.admin.controller;

import com.cykj.admin.annotation.MyLog;
import com.cykj.admin.service.IMenuService;
import com.cykj.admin.vo.MenuVO;
import com.cykj.common.dto.ResponseDTO;
import com.cykj.common.entity.MenuDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.admin.controller
 * @Author: 小小卢
 * @CreateTime: 2025-08-20 10:48
 * @Description: TODO
 * @Version: 1.0
 */
@Tag(name = "MenuController", description = "平台端菜单管理的接口")
@RestController
@RequestMapping("menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    /**
     * @Description: 构建树形菜单
     * @Param: [menuVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Operation(summary = "平台端构建树形菜单接口")
    @GetMapping("buildTreeMenu")
    public ResponseDTO buildTreeMenu(MenuVO menuVO) {
        return menuService.buildTreeMenu(menuVO);
    }

    @Operation(summary = "平台端查询所有菜单接口")
    @GetMapping("getAllMenu")
    public ResponseDTO getAllMenu() {
        return menuService.getAllMenu();
    }

    /**
     * @Description: 查询菜单
     * @Param: [menuVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Operation(summary = "平台端查询菜单接口")
    @GetMapping("getMenu")
    public ResponseDTO getMenuByAdmin(MenuVO menuVO) {
        return menuService.getMenuByAdmin(menuVO);
    }

    /**
     * @Description: 查询菜单Id
     * @Param: [menuVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Operation(summary = "平台端查询菜单Id接口")
    @GetMapping("getMenuId")
    public ResponseDTO getMenuId() {
        return menuService.getMenuId();
    }

    /**
     * @Description: 新增菜单
     * @Param: [menuVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @MyLog("新增菜单")
    @Operation(summary = "平台端新增菜单接口")
    @PostMapping("add")
    public ResponseDTO addMenu(@RequestBody MenuVO menuVO) {
        return menuService.addMenu(menuVO);
    }

    /**
     * @Description: 修改菜单
     * @Param: [menuVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @MyLog("修改菜单")
    @Operation(summary = "平台端修改菜单接口")
    @PostMapping("update")
    public ResponseDTO updateMenu(@RequestBody MenuVO menuVO) {
        return menuService.updateMenu(menuVO);
    }

    /**
     * @Description: 通过角色id获取角色对应菜单
     * @Param: [roleId]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Operation(summary = "通过角色id获取角色对应菜单")
    @Parameter(name = "roleId", description = "角色ID", required = true, in = ParameterIn.QUERY)
    @GetMapping("/getMenuById")
    public ResponseDTO getMenuById(@RequestParam("roleId") Integer roleId) {
        return menuService.getMenuById(roleId);
    }

    /**
     * @Description: 获取所有角色
     * @Param: []
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Operation(summary = "获取所有角色")
    @GetMapping("/getAllRole")
    public ResponseDTO getAllRole() {
        return menuService.getAllRole();
    }

    /**
     * @Description: 修改角色拥有的权限
     * @Param: [roleId]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @MyLog("修改角色权限")
    @Operation(summary = "修改角色拥有的权限")
    @PostMapping("/changePerMenu")
    public ResponseDTO changePerMenu(@RequestBody HashMap<String, Object> roleAndMenu) {
        return menuService.changePerMenu(roleAndMenu);
    }
}